package com.ultimatech.apigateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

/**
 * Created by zhangleping on 2017/9/27.
 */
@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
//@EnableResourceServer
public class ApiGatewayApp {

    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApp.class, args);
    }

//    @Configuration
//    protected static class OAuthSecurityConfig extends AuthorizationServerConfigurerAdapter {
//        @Autowired
//        private AuthenticationManager authenticationManager;
//        @Override
//        public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
//            endpoints.authenticationManager(authenticationManager);
//        }
//        @Override
//        public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
//            oauthServer.checkTokenAccess("isAuthenticated()");
//        }
//        @Override
//        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
////            clients.inMemory()
////                    .withClient("clientId")
////                    .secret("secretId")
////                    .authorizedGrantTypes("authorization_code", "client_credentials")
////                    .scopes("app");
//        }
//    }

//    @Configuration
//    @EnableWebSecurity
//    protected static class RestSecurityConfig extends WebSecurityConfigurerAdapter {
//        @Override
//        protected void configure(HttpSecurity http) throws Exception {
//            http.anonymous().disable()
//                    .sessionManagement()
//                    .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
//                    .and()
//                    .exceptionHandling()
////                    .accessDeniedHandler(accessDeniedHandler()) // handle access denied in general (for example comming from @PreAuthorization
////                    .authenticationEntryPoint(entryPointBean()) // handle authentication exceptions for unauthorized calls.
//                    .and()
//                    .authorizeRequests()
//                    .antMatchers("/oauth2/**").permitAll()
//                    .anyRequest().authenticated().and().csrf().disable();
//        }
//
//        //        @Bean
////        @Autowired
////        AccessDeniedHandler accessDeniedHandler() {
////            return new AccessDeniedExceptionHandler();
////        }
////
////        @Bean
////        @Autowired
////        AuthenticationEntryPoint entryPointBean() {
////            return new UnauthorizedEntryPoint();
////        }
//        // 不需要权限控制的路径
//        @Override
//        public void configure(WebSecurity web) throws Exception {
//            web.ignoring().antMatchers("/oauth2/**");
//        }
//    }

//    @Configuration
//    protected class ResourceServerConfig extends ResourceServerConfigurerAdapter {
//
//        private Logger log= LoggerFactory.getLogger(ResourceServerConfig.class);
//
////    @Autowired
////    private ResourceServerTokenServices tokenServices;
//
//        @Override
//        public void configure(HttpSecurity http) throws Exception {
////        http.authorizeRequests().antMatchers(HttpMethod.GET, "/hello").authenticated();
//            //.antMatchers(HttpMethod.POST, "/foo").hasAuthority("FOO_WRITE");
//            //you can implement it like this, but I show method invocation security on write
//
//        }
//
//        @Override
//        public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
//            log.info("==========================Configuring ResourceServerSecurityConfigurer ");
////        resources.resourceId("oauth2-resource");
////        resources.tokenServices(tokenServices);
//        }
//    }

}
